import {PageContainer} from "@ant-design/pro-components";
import PosterTable from "@/pages/Poster/components/PosterTable";
import {PosterVO, savePoster, updatePoster} from "@/services/PosterService";
import PosterUpdateModal from "@/pages/Poster/components/PosterUpdateModal";
import {useRef, useState} from "react";
import {message} from "antd";
import {ActionType} from "@ant-design/pro-table";
import {useSnapshot} from "@@/exports";
import {PosterModel} from "@/models/poster";


const Poster = () => {
    // 表格引用
    const tableRef = useRef<ActionType>()
    let posterState = useSnapshot(PosterModel.state);

    // 提交修改
    const onUpdateFinish = async (formData: any) => {
        let dto: PosterVO = JSON.parse(JSON.stringify(formData))
        // 字段处理

        let func = posterState.poster ? updatePoster : savePoster
        if (await func(dto)) {
            message.success("操作成功");
            // 刷新表格
            tableRef.current?.reload();
            return true;
        }
        return false;
    }

    return <PageContainer title="海报">
        {/*海报表格 开始*/}
        <PosterTable tableRef={tableRef} />
        {/*海报表格 结束*/}

        {/*修改模态框 开始*/}
        <PosterUpdateModal onFinish={onUpdateFinish}/>
        {/*修改模态框 结束*/}
    </PageContainer>
}

export default Poster
